package com.yida.system.controller;

import java.util.List;
import java.util.stream.Collectors;
import javax.servlet.http.HttpServletResponse;

import com.yida.common.core.enums.LimitTimeTypeEnum;
import com.yida.common.core.utils.poi.ExcelUtil;
import com.yida.common.core.web.controller.BaseController;
import com.yida.common.core.web.domain.AjaxResult;
import com.yida.common.core.web.page.TableDataInfo;
import com.yida.common.log.annotation.Log;
import com.yida.common.log.enums.BusinessType;
import com.yida.common.security.annotation.RequiresPermissions;
import com.yida.system.domain.request.SysBlackListEditRequest;
import com.yida.system.domain.request.SysBlackListSaveRequest;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.yida.system.api.domain.SysBlackList;
import com.yida.system.service.ISysBlackListService;


/**
 * 系统黑名单Controller
 * 
 * @author wws
 * @date 2023-03-22
 */
@RestController
@RequestMapping("/system/black")
@Api(tags = "系统黑名单管理")
public class SysBlackListController extends BaseController
{
    @Autowired
    private ISysBlackListService sysBlackListService;

    /**
     * 查询系统黑名单列表
     */
    @RequiresPermissions("system:black:list")
    @GetMapping("/list")
    @ApiOperation(value = "分页查询",response = SysBlackList.class)
    public TableDataInfo list(SysBlackList sysBlackList)
    {
        startPage();
        List<SysBlackList> list = sysBlackListService.selectSysBlackListList(sysBlackList);
        return getDataTable(list);
    }

    /**
     * 导出系统黑名单列表
     */
    @RequiresPermissions("system:black:export")
    @Log(title = "系统黑名单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ApiOperation("导出系统黑名单")
    public void export(HttpServletResponse response, SysBlackList sysBlackList)
    {
        List<SysBlackList> list = sysBlackListService.selectSysBlackListList(sysBlackList).stream().map(item -> {
            item.setLimitTimeType(LimitTimeTypeEnum.getDescByType(item.getLimitTimeType()));
            return item;
        }).collect(Collectors.toList());
        ExcelUtil<SysBlackList> util = new ExcelUtil<SysBlackList>(SysBlackList.class);
        util.exportExcel(response, list, "系统黑名单数据");
    }

    /**
     * 获取系统黑名单详细信息
     */
    @RequiresPermissions("system:black:list")
    @GetMapping(value = "/{id}")
    @ApiOperation(value = "详情",response = SysBlackList.class)
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(sysBlackListService.selectSysBlackListById(id));
    }

    /**
     * 新增系统黑名单
     */
    @RequiresPermissions("system:black:save")
    @Log(title = "系统黑名单", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation(value = "新增系统黑名单")
    public AjaxResult add(@RequestBody @Validated SysBlackListSaveRequest saveRequest)
    {
        return toAjax(sysBlackListService.insertSysBlackList(saveRequest));
    }

    /**
     * 修改系统黑名单
     */
    @RequiresPermissions("system:black:edit")
    @Log(title = "系统黑名单", businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiOperation(value = "修改系统黑名单")
    public AjaxResult edit(@RequestBody SysBlackListEditRequest editRequest)
    {
        return toAjax(sysBlackListService.updateSysBlackList(editRequest));
    }

    /**
     * 删除系统黑名单
     */
    @RequiresPermissions("system:black:delete")
    @Log(title = "系统黑名单", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    @ApiOperation("删除系统黑名单")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(sysBlackListService.deleteSysBlackListByIds(ids));
    }
}
